/*
 * @Author: likang xie 
 * @Date: 2018-06-15 11:39:55 
 * @Purpose: 登录
 */

(function () {

  // 全局变量
  var $ = null;
  var form = null;
  var submiting = false;
  var phone = '';

  // 使用模块
  layui.use(['jquery', 'form'], function () {
    $ = layui.$;
    form = layui.form;
    btgo.getRsa($);
    bindEvent(); // 绑定事件
  });

  // 绑定事件
  function bindEvent() {
    // 获取验证码
    $('.code-btn').on('click', getCode);
    // 提交事件
    form.on('submit(submit)', function (data) {
      var formdata = data.field;
      console.log(formdata);
      !submiting && submit(formdata);
    });
    // 回车键
    btgo.enter($, {
      el: '.form-container',
      callback: function callback() {
        $('.submit-btn').click();
      }
    });
  }

  // 获取验证码
  function getCode() {
    phone = $('input[name="phone"]').val();
    if (phone) {
      var url = '/agents/ajax/smscode';
      btgo.request($, {
        url: url,
        data: {
          phone: phone
        },
        success: function success(res) {
          console.log(res);
        }
      });
    } else {
      btgo.msg('请输入手机号码');
    }
  }

  // 提交
  function submit(form) {}
})();